<template>
  <div id="bingmap-container"></div>
</template>

<script>
import * as Cesium from 'cesium';
export default {
  data() {
    return {
      viewer: null
    };
  },

  mounted() {
    const viewer = new Cesium.Viewer('bingmap-container', {
      geocoder: true, // 搜索按钮，
      homeButton: false, // 跳转主页按钮
      sceneModePicker: false, // 是否开启平面图选择
      navigationHelpButton: false, // 操作帮助按钮
      baseLayerPicker: true // 地图选择按钮
    });
    this.viewer = viewer;
    /**
     * 设置默认底图
     */
    // cesium 默认提供的所有图层
    // console.log(viewer.baseLayerPicker.viewModel.imageryProviderViewModels);
    viewer.baseLayerPicker.viewModel.selectedImagery = viewer.baseLayerPicker.viewModel.imageryProviderViewModels[0];
    //  去除水印
    viewer._cesiumWidget._creditContainer.style.display = 'none';
    // 设置初始位置
    // viewer.camera.setView({
    //   destination: Cesium.Cartesian3.fromDegrees(108.96403324890136, 34.21910415331429, 5000)
    // });
    // 设置相机角度

    /**
     * 加载 3dTileS
     */
    var tower = new Cesium.Cesium3DTileset({ url: '3dTiles/tower/tileset.json' });
    viewer.scene.primitives.add(tower);
    tower.readyPromise
      .then(function (currentModel) {
        viewer.scene.globe.depthTestAgainstTerrain = true;
        //
        viewer.camera.flyTo({
          destination: Cesium.Cartesian3.fromDegrees(108.95898403, 34.22207811, 724.47624957),
          orientation: {
            heading: Cesium.Math.toRadians(163.47), // 方向
            pitch: Cesium.Math.toRadians(-55.04), // 倾斜角度
            roll: 0
          }
        });

        viewer.zoomTo(currentModel, new Cesium.HeadingPitchRange(-0.5, -0.5, 100));
      })
      .otherwise(function (error) {
        new Error(error);
      });
  }
};
</script>

<style lang="scss" scoped>
#bingmap-container {
  height: 100%;
  position: relative;
}
</style>
